package com.srb.core.service.impl;

import com.alibaba.excel.util.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.srb.core.pojo.entity.BorrowerAttach;
import com.srb.core.mapper.BorrowerAttachMapper;
import com.srb.core.pojo.vo.BorrowerAttachVo;
import com.srb.core.service.BorrowerAttachService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 借款人上传资源表 服务实现类
 * </p>
 *
 * @author dapeng
 * @since 2021-08-08
 */
@Service
public class BorrowerAttachServiceImpl extends ServiceImpl<BorrowerAttachMapper, BorrowerAttach> implements BorrowerAttachService {

    @Override
    public List<BorrowerAttachVo> selectBorrowerAttachVoList(Long borrowerId) {
        QueryWrapper<BorrowerAttach> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("borrower_id",borrowerId);
        List<BorrowerAttach> list = baseMapper.selectList(queryWrapper);
        if (CollectionUtils.isEmpty(list)){
            return Collections.EMPTY_LIST;
        }
        List<BorrowerAttachVo> voList = new ArrayList<>(list.size());
        for (BorrowerAttach borrowerAttach : list) {
            BorrowerAttachVo borrowerAttachVo = new BorrowerAttachVo();
            borrowerAttachVo.setImageUrl(borrowerAttach.getImageUrl());
            borrowerAttachVo.setImageType(borrowerAttach.getImageType());
            voList.add(borrowerAttachVo);
        }
        return voList;
    }
}
